package User.dao.impl;

import User.dao.UserDao;
import User.model.User;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * Created by Новак on 21.11.2014.
 */
public class UserDaoImpl  extends HibernateDaoSupport implements UserDao{

    public void save(User user){
        getHibernateTemplate().save(user);
    }
    public void update(User user){
        getHibernateTemplate().update(user);
    }
    public void delete(User user){
        getHibernateTemplate().delete(user);
    }
    public User getUserByLogin (String login, String pass){
        List list = getHibernateTemplate().find("from User where login='"+login+"'"+" and pass='"+pass+"'");
        if(list.size()!=0){
            return (User)list.get(0);}

        return null;
    }

    @Override
    public List getAllUser() {
        List list=getHibernateTemplate().find("from User");
        return list;
    }

    @Override
    public boolean checkLogin(String login) {
        List list =getHibernateTemplate().find("from User where login='"+login+"'");
        if(list.size()==0){
            return false;
        }
        else{
            return true;
        }

    }
}
